package com.woniu.microworkorderserver.workadminmag.controller;


import com.woniu.microcommonsserver.entity.WorkListInfoEntity;
import com.woniu.microcommonsserver.param.ResponseMsg;
import com.woniu.microworkorderserver.workadminmag.service.WorDispatchService;
import org.apache.ibatis.mapping.ResultMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/wordispatch")//工单调度的控制层
public class WorDispatchContro {

    @Resource
    private WorDispatchService worDispatchServiceimpl;


    /**
     * 根据传的参数进行查询，六种状态   待审，已接单，待派，进行中，复核，完成
     * @param status
     * @return
     */
    @GetMapping(value="/success",produces = {"application/json;charset=utf-8"})
    public List<WorkListInfoEntity> findAll(String status){

        System.out.println(status);

        List<WorkListInfoEntity>  zt =  worDispatchServiceimpl.findAll(status);

        return zt;

    }


    /**
     * 已结单数据通过退单按钮变为待审中
     * @param id
     * @return
     */
    @GetMapping(value = "/updateById",produces = {"application/json;charset=utf-8"})
    public  ResponseMsg updateFishedAccept(int id){

//        System.out.println(id);

        ResponseMsg success = new ResponseMsg(200,"修改成功","");

        worDispatchServiceimpl.updateFishedAccept(id);



        return success;
    }
    @GetMapping(value = "/allowWork",produces = {"application/json;charset=utf-8"})
    public ResponseMsg allowWork(int id){

//        System.out.println("点击通过之后传过来的Id="+id);

        worDispatchServiceimpl.allowWork(id);

        ResponseMsg success = new ResponseMsg(200,"成功通过","");

        return success;
    }

    @GetMapping(value = "/rejectWork",produces = {"application/json;charset=utf-8"})
    public ResponseMsg rejectWork(int id){


        worDispatchServiceimpl.rejectWork(id);

        ResponseMsg success = new ResponseMsg(200,"成功通过","");

        return success;
    }



    //新增查询按钮
    @GetMapping(value = "/insertRepair",produces = {"application/json;charset=utf-8"})
    public ResponseMsg insertRepair(WorkListInfoEntity workListInfoEntity){

        //以时间戳为订单号
        String wrkCrti = new Date().getTime()+"";

        workListInfoEntity.setWrkNum(wrkCrti);

        worDispatchServiceimpl.insertRepair(workListInfoEntity);

        //System.out.println(workListInfoEntity.getRepairTelphone());

        ResponseMsg success = new ResponseMsg(200,"成功通过","");

        return success;
    }

    //派单按钮
    @RequestMapping(value = "/saveInsert",produces = {"application/json;charset=utf-8"})
    public ResponseMsg saveInsert(@RequestBody WorkListInfoEntity workListInfoEntity){


       // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

//        Date date =  simpleDateFormat.parse();
        //String sd = simpleDateFormat.format(workListInfoEntity.getActrulStart());

        //System.out.println(workListInfoEntity);

       // System.out.println(workListInfoEntity.getActrulStart());

        worDispatchServiceimpl.saveInsert(workListInfoEntity);


        ResponseMsg success = new ResponseMsg(200,"成功通过","");

        return success;
    }

    //stopingById

    @GetMapping(value = "/stopingById",produces = {"application/json;charset=utf-8"})
    public ResponseMsg stopingById(int id){


        worDispatchServiceimpl.stopingById(id);

        ResponseMsg success = new ResponseMsg(200,"成功通过","");

        return success;
    }


}
